import {z} from 'zod' export type User = {email?: string | undefined, id?: string | undefined, type?: ('user' | 'api_key' | 'internal') | undefined}; export type CuePoint = {force_stop?: boolean | undefined, metadata?: string | undefined, name?: string | undefined, time: number, type: 'AD' | 'DATA'}; export type Geo = {countries: Array, exclude_countries: boolean, restricted: boolean}; export type VideoImages = Record; export type Link = {text?: string | undefined, url?: string | undefined}; export type Schedule = {ends_at?: (string | null) | undefined, starts_at?: (string | null) | undefined}; export type Sharing = {by_external_acct?: boolean | undefined, by_id?: string | undefined, by_reference?: boolean | undefined, source_id?: string | undefined, to_external_acct?: boolean | undefined}; export type TextTrack = {default?: boolean | undefined, id?: string | undefined, kind?: ('subtitles' | 'captions' | 'descriptions' | 'chapters' | 'metadata' | 'transcripts') | undefined, label?: string | undefined, mime_type?: string | undefined, src?: string | undefined, srclang?: string | undefined, status: unknown}; export type Transcript = {id?: string | undefined, account_id?: string | undefined, default?: boolean | undefined, label?: string | undefined, sources?: Array | undefined, src: string, srclang: string, status?: ('draft' | 'published') | undefined}; export type VideoVariants = Array; export type Video = {ad_keys?: (string | null) | undefined, clip_source_video_id?: string | undefined, complete?: boolean | undefined, created_at?: string | undefined, created_by?: User | undefined, cue_points?: Array | undefined, custom_fields?: {[key: string]: string} | undefined, delivery_type?: ('remote' | 'dynamic_origin' | 'live_origin' | 'unknown') | undefined, description?: string | undefined, digital_master_id?: string | undefined, drm_disabled?: boolean | undefined, duration?: number | undefined, economics?: ('AD_SUPPORTED' | 'FREE') | undefined, folder_id?: string | undefined, forensic_watermarking?: ('ACTIVE' | 'UNAVAILABLE') | undefined, geo?: Geo | undefined, has_digital_master?: boolean | undefined, id?: string | undefined, images?: VideoImages | undefined, labels?: Array | undefined, link?: Link | undefined, long_description?: string | undefined, name?: string | undefined, offline_enabled?: boolean | undefined, original_filename?: string | undefined, playback_rights_id?: string | undefined, projection?: ('equirectangular' | null) | undefined, published_at?: string | undefined, reference_id?: (string | null) | undefined, schedule?: Schedule | undefined, sharing?: Sharing | undefined, state?: ('ACTIVE' | 'INACTIVE' | 'PENDING' | 'DELETED') | undefined, tags?: Array | undefined, text_tracks?: Array | undefined, transcripts?: Array | undefined, updated_at?: string | undefined, updated_by?: User | undefined, variants?: VideoVariants | undefined}; export type PatchApiV1AccountsAccountIdVideosVideoIdArgs = {account_id: string, video_id: string, 'Content-Type': string, Authorization: string, body: Video}; export type PatchApiV1AccountsAccountIdVideosVideoIdOptions = {baseUrl?: string | undefined, BCOAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const user = z.object({email: z.string().optional(), id: z.string().optional(), type: z.enum(["user", "api_key", "internal"]).optional()}); export const cuePoint = z.object({force_stop: z.boolean().optional(), metadata: z.string().max(512).optional(), name: z.string().optional(), time: z.number(), type: z.enum(["AD", "DATA"])}); export const geo = z.object({countries: z.array(z.string()), exclude_countries: z.boolean(), restricted: z.boolean()}); export const videoImages = z.object({}); export const link = z.object({text: z.string().max(255).optional(), url: z.string().max(255).optional()}); export const schedule = z.object({ends_at: z.string().nullable().optional(), starts_at: z.string().nullable().optional()}); export const sharing = z.object({by_external_acct: z.boolean().optional(), by_id: z.string().optional(), by_reference: z.boolean().optional(), source_id: z.string().optional(), to_external_acct: z.boolean().optional()}); export const textTrack = z.object({default: z.boolean().optional(), id: z.string().optional(), kind: z.enum(["subtitles", "captions", "descriptions", "chapters", "metadata", "transcripts"]).optional(), label: z.string().optional(), mime_type: z.string().optional(), src: z.string().optional(), srclang: z.string().optional(), status: z.unknown()}); export const transcript = z.object({id: z.string().optional(), account_id: z.string().optional(), default: z.boolean().optional(), label: z.string().optional(), sources: z.array(z.string()).optional(), src: z.string(), srclang: z.string(), status: z.enum(["draft", "published"]).optional()}); export const videoVariants = z.array(z.unknown()); export const video = z.object({ad_keys: z.string().nullable().optional(), clip_source_video_id: z.string().optional(), complete: z.boolean().optional(), created_at: z.string().optional(), created_by: user.optional(), cue_points: z.array(cuePoint).optional(), custom_fields: z.record(z.string(), z.string()).optional(), delivery_type: z.enum(["remote", "dynamic_origin", "live_origin", "unknown"]).optional(), description: z.string().max(248).optional(), digital_master_id: z.string().optional(), drm_disabled: z.boolean().optional(), duration: z.number().int().optional(), economics: z.enum(["AD_SUPPORTED", "FREE"]).optional(), folder_id: z.string().optional(), forensic_watermarking: z.enum(["ACTIVE", "UNAVAILABLE"]).optional(), geo: geo.optional(), has_digital_master: z.boolean().optional(), id: z.string().optional(), images: videoImages.optional(), labels: z.array(z.string()).optional(), link: link.optional(), long_description: z.string().max(5000).optional(), name: z.string().min(1).max(255).optional(), offline_enabled: z.boolean().optional(), original_filename: z.string().optional(), playback_rights_id: z.string().optional(), projection: z.literal("equirectangular").nullable().optional(), published_at: z.string().optional(), reference_id: z.string().max(150).nullable().optional(), schedule: schedule.optional(), sharing: sharing.optional(), state: z.enum(["ACTIVE", "INACTIVE", "PENDING", "DELETED"]).optional(), tags: z.array(z.string().max(128)).optional(), text_tracks: z.array(textTrack).optional(), transcripts: z.array(transcript).optional(), updated_at: z.string().optional(), updated_by: user.optional(), variants: videoVariants.optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Update Video * * PATCH /v1/accounts/{{account_id}}/videos/{{video_id}} */ export const patchApiV1AccountsAccountIdVideosVideoId = async (args: PatchApiV1AccountsAccountIdVideosVideoIdArgs, options?: PatchApiV1AccountsAccountIdVideosVideoIdOptions) => { const {baseUrl = "https://cms.api.brightcove.com", fetch: fetchFn = fetch, BCOAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (BCOAuth2 !== undefined) headers.set('authorization', `Bearer ${BCOAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/accounts/${encodeURIComponent(String(args['{account_id']))}}/videos/${encodeURIComponent(String(args['{video_id']))}}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(video, await res.json()) };